package com.ziyucoding.springboot.labs.lab12.uidprovider.controller;

import com.ziyucoding.springboot.labs.lab12.uidprovider.service.UidGeneratorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 全局唯一键 控制器
 *
 * @author ziyucoding
 * @date 2022-11-17
 **/
@RestController
@RequestMapping("/uid")
public class UidController {

    @Autowired
    private UidGeneratorService uidGeneratorService;

    /**
     * 生成全局唯一键
     *
     * @return Map<String, Object>
     **/
    @GetMapping("/generate-uid")
    public Map<String, Object> generateUid() {
        Long uid = uidGeneratorService.generateUid();
        Map<String, Object> result = new HashMap<>();
        result.put("code", 0);
        result.put("msg", "成功");
        result.put("data", uid);
        return result;
    }

}
